using UnityEngine;
using System.Collections;

public class Bomb : MonoBehaviour 
{
	public AudioSource bombDestroySound;
	public int moveSpeed = 20;
	Vector3 moveDirection = new Vector3(0,-1,0);
	public ScoreKeeper scoreKeeper;
	public int destroyCount = 0;
	
	// Use this for initialization
	void Start () 
	{
		scoreKeeper = FindObjectOfType(typeof(ScoreKeeper)) as ScoreKeeper;
	}
	
	// Update is called once per frame
	void Update () 
	{
		Vector3 newPosition = moveDirection * (moveSpeed * Time.deltaTime);
		transform.position = transform.position + newPosition;
		
		if(transform.position.y < -16)
		{
			bombDestroySound.Play();
			Destroy(transform.gameObject);
			destroyCount++;
			scoreKeeper.SubtractScore();
			scoreKeeper.LostTry();
			
			if(scoreKeeper.playerTrys == 0)
			{
				Application.LoadLevel("MainMenu");
			}
		}
	}
	
	void OnTriggerEnter(Collider collision)
	{
		bombDestroySound.Play();
		Destroy(transform.gameObject);
		destroyCount++;
		scoreKeeper.AddScore();
	}
}
